package com.Interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2017/9/1.
 */
public class CrossInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String accesstoken =  request.getHeader("accessToken");
            System.out.println("----------------------------"+accesstoken+"----------------------------");
        if(accesstoken!=null&&!accesstoken.equals("")){
        }
        response.setHeader("Access-Control-Allow-Origin","*");//跨域
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Authorization,Origin, X-Requested-With, Content-Type, Accept,accessToken");
        response.setHeader("X-Powered-By","3.2.1");
        response.setHeader("Content-Type", "application/json;charset=utf-8");
        return true;
    }
}
